@extends('Admin.layouts.application')
@section('css')
    <link rel="stylesheet" href="/assets/xSystem/vendor/daterangepicker/daterangepicker.css">
    <style>
        .am-modal-bd{
            border-bottom:none;
            padding: 0px 0px 0px 0px;
        }
        .am-icon-spin{
            font-size: 2.6rem;
            margin-bottom: 15px;
        }
        .fixed-layout .admin-header{
            z-index: 1000;
        }
</style>
@endsection
@section('content')
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding am-padding-bottom-0">
                <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">添加网络视频</strong> /
                    <small>Add network video</small>
                </div>
            </div>

            <hr>
            @include('Admin.layouts._flash')
            <div class="am-g" style="height: 37px;">

                <div class="am-u-sm-12 am-u-md-12">
                    <div class="am-btn-toolbar ">
                        <div class="am-btn-group am-btn-group-xs">
                            {{--@if(Request::input('video_category_id')==1){
                            @foreach($categories as $category)
                                @if($category->name=="电影"){
                                <optgroup label="{{$category->name}}">
                                    @foreach($category->children as $c)
                                        <option value="{{$c->id}}"
                                                @if($c->id == Request::input('category_id')) selected @endif>
                                            {{$c->name}}
                                        </option>
                                    @endforeach
                                    @endif
                                    @endforeach
                                    @else
                                        @foreach($categories as $category)
                                            @if($category->name=="电视剧"){
                                            <optgroup label="{{$category->name}}">
                                                @foreach($category->children as $c)
                                                    <option value="{{$c->id}}"
                                                            @if($c->id == Request::input('category_id')) selected @endif>
                                                        {{$c->name}}
                                                    </option>
                                                @endforeach
                                                @endif

                                                @endforeach

                                                @endif--}}


                            <a type="button" class="am-btn am-btn-success am-btn-xl" style="height: 32px" href=""id="destroy_checked">
                                <span class="am-icon-plus"></span> 添加视频
                            </a>
                            <a type="button" class="am-btn am-btn-primary am-btn-xl" id="onekey_video" data-am-modal="{target: '#your-modal', closeViaDimmer: 0}" style="height: 32px" href="javascript:void(0)">
                                <span class="am-icon-plus"></span> 一键添加热门电视剧
                            </a>
                            <a type="button" class="am-btn am-btn-danger am-btn-xl" id="add_movie" data-am-modal="{target: '#your-modal', closeViaDimmer: 0}"  style="height: 32px" href="javascript:void(0)">
                                <span class="am-icon-plus"></span> 一键添加热门电影
                            </a>
                            <a type="button" class="am-btn am-btn-warning am-btn-xl" id="add_variety" data-am-modal="{target: '#your-modal', closeViaDimmer: 0}"   style="height: 32px" href="javascript:void(0)">
                                <span class="am-icon-plus"></span> 一键添加热门综艺
                            </a>
                        </div>
                    </div>



                </div>
            </div>
            <div class="am-g">
                <div class="am-u-sm-12 am-u-md-12">
                    <form class="am-form-inline" id="form" action="{{url("video/youku_video_list")}}" role="form" method="get">

                        <div class="am-form-group">
                            <input type="text" id="name" name="name" class="am-form-field am-input-sm" placeholder="视频名称"
                                   value="{{ Request::input('name') }}">
                        </div>

                        <div class="am-form-group">
                            <select data-am-selected="{btnSize: 'sm', maxHeight: 360}"
                                    name="video_category_id" id="category_id">
                                @foreach($categories as $category)

                                    <option value="{{$category->id}}"
                                            @if($category->id == Request::input('video_category_id')) selected @endif>
                                        {{$category->name}}
                                    </option>

                                @endforeach
                            </select>

                        </div>
                        <button type="submit" class="am-btn am-btn-default am-btn-sm">查询</button>
                    </form>
                </div>

            </div>
            <div class="am-g">
                <div class="am-u-sm-12">


                        <table class="am-table am-table-striped am-table-hover table-main">
                            <thead>
                            <tr>
                                <th class="table-check"></th>
                                <th class="table-id" style="width: 100px;">视频名称</th>
                                <th class="table-thumb">封面图</th>
                                <th class="table-title">分类</th>
                                <th class="table-title">上映时间</th>
                                <th class="table-title">描述</th>
                                <th class="table-category">评分</th>
                                <th class="table-set">操作</th>

                            </tr>
                            </thead>
                            <tbody>
                                @if(!empty($datas))
                                    @foreach ($datas as $data)

                                        <tr data-id="{{$data['id']}}">
                                            <td><input type="checkbox" class="checked_id"
                                                       name="checked_id"/></td>
                                            <td id="title{{$data["id"]}}" data-name="{{$data['name']}}">{{$data['name']}}</td>
                                            <td id="thumb{{$data["id"]}}" data-thumb="{{$data['poster']}}">
                                                <img width="100" height="50" src="{{$data['poster']}}" alt="">
                                            </td>
                                            <td id="showcategory{{$data["id"]}}" data-showcategory="{{$data['showcategory']}}">
                                                {{$data['showcategory']}}
                                            </td>
                                            <td id="published{{$data["id"]}}" data-published="{{$data['published']}}">
                                                {{$data['published']}}
                                            </td>

                                            <td id="desc{{$data["id"]}}" data-desc="{{$data['description']}}">
                                                {{$data['description']}}
                                            </td>
                                            <td>
                                                {{$data['score']}}
                                            </td>

                                            <td id="link{{$data["id"]}}" data-link="{{$data['play_link']}}">
                                                <div class="am-btn-toolbar">
                                                    <div class="am-btn-group am-btn-group-xs">
                                                        <a class="am-btn am-btn-default am-btn-xs am-text-secondary"
                                                           href="{{$data['play_link']}}" target="_blank">
                                                            <span class="am-icon-pencil-square-o"></span> 试看
                                                        </a>
                                                    </div>
                                                </div>
                                            </td>
                                        </tr>

                                    @endforeach
                                @endif
                                @if(!empty($video_datas))
                                    @foreach ($video_datas as $data)

                                        <tr data-id="{{$data['id']}}">
                                            <td></td>
                                            <td id="title{{$data["id"]}}" data-name="{{$data['name']}}">{{$data['name']}}</td>
                                            <td id="thumb{{$data["id"]}}" data-thumb="{{$data['thumb']}}">
                                                <img width="100" height="50" src="{{$data['thumb']}}" alt="">
                                            </td>
                                            <td id="showcategory{{$data["id"]}}" data-showcategory="{{$data['genre']}}">
                                                {{$data['genre']}}
                                            </td>
                                            <td>
                                                {{$data['published']}}
                                            </td>
                                            <td id="desc{{$data["id"]}}" data-desc="{{$data['desc']}}">
                                                {{cut_utf8($data['desc'],20)}}
                                            </td>
                                            <td>
                                                {{round($data['score'],2)}}
                                            </td>

                                            <td id="link{{$data["id"]}}" data-link="{{$data['url']}}">
                                                <div class="am-btn-toolbar">
                                                    <div class="am-btn-group am-btn-group-xs">
                                                        <a class="am-btn am-btn-default am-btn-xs am-text-secondary"
                                                           href="{{$data['url']}}" target="_blank">
                                                            <span class="am-icon-pencil-square-o"></span> 试看
                                                        </a>
                                                    </div>
                                                </div>
                                            </td>
                                        </tr>

                                    @endforeach
                                @endif
                            </tbody>
                        </table>

                        <hr/>
                </div>

            </div>
        </div>

            <div class="am-modal am-modal-prompt" tabindex="-1" id="my-prompt">
                <div class="am-modal-dialog">
                    <div class="am-modal-hd">添加电视剧</div>
                    <div class="am-modal-bd" style="color: red;">
                        清选择优酷视频地址
                        <input id="url" type="text" class="am-modal-prompt-input">
                    </div>
                    <div class="am-modal-footer">
                        <span class="am-modal-btn" data-am-modal-cancel>取消</span>
                        <span id="btn" type="submit" class="am-modal-btn">提交</span>
                    </div>
                </div>
            </div>
        </form>
        @include('Admin.layouts._footer')
    </div>



    <div class="am-modal am-modal-alert" tabindex="-1" id="your-modal">
        <div class="am-modal-dialog" style="width: 400px;">
            <div class="am-g">
                <div class="am-u-md-12" style=" padding-right: 0px;padding-left: 0px;">
                    <div class="am-alert am-alert-warning" style="border: none;">
                        <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
                        提示
                    </div>
                </div>
            </div>
            <div class="am-modal-bd">
                <div class="am-modal-hd">正在加载视频请稍后......</div>
                <span class="am-icon-spinner am-icon-spin"></span>
            </div>

        </div>
    </div>


@endsection

@section('js')
    <script src="/assets/xSystem/vendor/daterangepicker/moment.js"></script>
    <script src="/assets/xSystem/vendor/moment/locale/zh-cn.js"></script>
    <script src="/assets/xSystem/vendor/daterangepicker/daterangepicker.js"></script>
    <script src="/assets/xSystem/js/daterange_config.js"></script>
    <script>
        $(function() {
            function show_add_movie(){
                $("#add_movie").removeClass('am-disabled');
                $("#onekey_video").removeClass('am-disabled');
                $("#add_variety").removeClass('am-disabled');
            }
            function show_onekey_video(){
                $("#add_movie").removeClass('am-disabled');
                $("#onekey_video").removeClass('am-disabled');
                $("#add_variety").removeClass('am-disabled');
            }
            function show_add_variety(){
                $("#add_movie").removeClass('am-disabled');
                $("#onekey_video").removeClass('am-disabled');
                $("#add_variety").removeClass('am-disabled');
            }

            $("#add_movie").click(function(){
                $(this).addClass('am-disabled');
                var $modal = $('#your-modal');
                $("#onekey_video").addClass('am-disabled');
                $("#add_variety").addClass('am-disabled');
                setInterval(show_add_movie,3000);
                $.ajax({
                    type: "get",
                    url: "/video/add_movie",
                    success: function () {
                        $modal.modal('close');
                        location.href = '/video';
                    }
                });
            });

            $("#onekey_video").click(function(){
                $(this).addClass('am-disabled');
                var $modal = $('#your-modal');
                $("#add_movie").addClass('am-disabled');
                $("#add_variety").addClass('am-disabled');
                setInterval(show_onekey_video,3000);
                $.ajax({
                    type: "get",
                    url: "/video/onekey_video",
                    success: function () {
                        //$modal.modal('close');
                        //location.href = '/video';
                    }
                });

            });

            $("#add_variety").click(function(){
                $(this).addClass('am-disabled');
                var $modal = $('#your-modal');
                $("#add_movie").addClass('am-disabled');
                $("#onekey_video").addClass('am-disabled');
                setInterval(show_add_variety,3000);
                $.ajax({
                    type: "get",
                    url: "/video/add_variety",
                    success: function () {
                        $modal.modal('close');
                        location.href = '/video';
                    }

                });

            });


            $('#doc-prompt-toggle').on('click', function() {
                $('#my-prompt').modal({
                    //relatedTarget: this,
                    onConfirm: function(e) {

                    },
                });
            });
        });

        $('#btn').click(function () {
            var data = {
                url: $("#url").val(),
            };

            console.log(data);
            $.ajax({
                type: "post",
                url: "/video/create_video",
                data: data,
                success: function (data) {
                    /*if(data.status==0){
                        alert(data.info);
                    }else{
                        alert('添加成功');
                    }
                    //location.href = '/video';*/
                }
            });
        });

        $('#destroy_checked').click(function () {

                var length = $(".checked_id:checked").length;
                if (length == 0) {
                    alert("您必须至少选中一条!");
                    return false;
                }

                if($('#category_id').val() == -1){
                    alert("添加视频前请选择添加的分类");
                    return false;
                }

                if (length > 1) {
                    alert("您一次只能添加一部电影!");
                    return false;
                }

                var id=$(".checked_id:checked").parents("tr").data('id');
                var data = {
                    id: $(".checked_id:checked").parents("tr").data('id'),
                    name: $("#title"+id+"").data('name'),
                    category_id: $("#category_id").val(),
                    desc: $("#desc"+id+"").data('desc'),
                    showcategory: $("#showcategory"+id+"").data('showcategory'),
                    published: $("#published"+id+"").data('published'),
                    thumb: $("#thumb"+id+"").data('thumb'),
                    link: $("#link"+id+"").data('link'),
                };
                console.log(data);

                $.ajax({
                    type: "post",
                    url: "/video/checked_video",
                    data: data,
                    success: function (data) {
                        if(data.status==0){
                            alert(data.info);
                        }else{
                            alert("添加成功");
                        }
                    }
                });
        });

        $("#form").submit(function () {

            if($('#name').val() ==""){
                alert('视频名称不能为空')
                return false;
            }
        });
        //排序
        $("input[name='sort_order']").change(function () {
            var data = {
                sort_order: $(this).val(),
                id: $(this).parents("tr").data('id')
            };
            console.log(data);
            $.ajax({
                type: "PATCH",
                url: "/video/sort_order",
                data: data,
            });
        });
       
    </script>

@endsection





